package GUI;
/**
 * Select a student for the prent user if he has more then one kid registered
 */

import java.util.Vector;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import Common.StudentClass;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SelectStudentForParent extends JPanel {
	
	private JComboBox cBSelStudent = null;
	private JLabel lblSelectStudent = null;
	private JButton btnNext=null;
	
	public String selectedStudent=null;
	public Login myLoginFrame = null;
	public UserParent user=null;
	public ParentMainMenu pmn=null;
	private Vector<String> data=null;
	private int i=0;
	private ParentViewPersonalData pvpd = null;
	
	
	
	public SelectStudentForParent(ParentMainMenu pmn) {
		super();
		initialize(pmn);
			
	}
	
	
	public JButton getNextButton()
	{
		if(btnNext==null)
		{
			btnNext = new JButton("Next");
			btnNext.setBounds(324, 230, 89, 23);
			btnNext.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					pmn.user.SetName(selectedStudent);
					pvpd = null;
					pvpd = pmn.getParentViewPersonalDataPanel();
				pmn.setContentPane(pvpd);
				for(i=0;i<pmn.user.StudentsData.size();i++)
				{
					if(selectedStudent.endsWith(pmn.user.StudentsData.get(i).Sid)&&(pmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.isEmpty()))
					{
						JOptionPane.showMessageDialog(pmn.pSelStud, "No courses available for: "+pmn.user.StudentsData.get(i).FirstName +" "+pmn.user.StudentsData.get(i).LastName +" "+pmn.user.StudentsData.get(i).Sid);
						pmn.setContentPane(pmn.getEmptyScr());
						
					}
					
				}
				//pmn.pViewPD.myLoginFrame=pmn.myLoginFrame;
					
				}
			});
			
		}
		
		return btnNext;
			
	}
	private void initialize(ParentMainMenu pmn)
	{
		setLayout(null);
		lblSelectStudent = new JLabel("Select Student:");
		lblSelectStudent.setBounds(45, 84, 74, 14);
		
		add(lblSelectStudent);
		add(getSelStudentCb(pmn.user.StudentsData));
		add(getNextButton());
		
	}
	
	
	
	public JComboBox getSelStudentCb(final Vector<StudentClass> KidName)
	{
		
		data = new Vector<String>();
		for(i=0;i<KidName.size();i++)
		{
			data.add(KidName.get(i).FirstName +" "+KidName.get(i).LastName +" "+KidName.get(i).Sid);
			
		}
		
		cBSelStudent  = new JComboBox(data);
		cBSelStudent.setBounds(139, 81, 243, 20);
		//cBSelStudent.insertItemAt("Select Student", 1);
		cBSelStudent.addActionListener(new java.awt.event.ActionListener() {
	
		public void actionPerformed(java.awt.event.ActionEvent e) {
		selectedStudent= cBSelStudent.getSelectedItem().toString();
		
		
		
		System.out.println(selectedStudent);
		 
		
		
		 	}
		
	
		});

		return cBSelStudent;
	}
	
	
}
